var prefix = ctx + "manage/rewardRecord";

$(function () {
    var options = {
        url: prefix + "/list",
        queryParams: queryParams,
        columns: [
            {
                checkbox: true
            },
            {
                field: 'usId',
                title: '用户ID'
            },
            {
                field: 'usNickname',
                title: '用户名'
            },
            {
                field: 'pusId',
                title: '徒弟ID'
            },
            {
                field: 'rrMoney',
                title: '奖励'
            },
            {
                field: 'rrType',
                title: '奖励类型',
                formatter: function (value, row, index) {
                    if (value === 1) {
                        return '<span class="badge badge-warning">金币</span>';
                    }
                    if (value === 2) {
                        return '<span class="badge badge-danger">红包</span>';
                    }
                    if (value === 3) {
                        return '<span class="badge badge-warning">金币佣金</span>';
                    }
                    if (value === 4) {
                        return '<span class="badge badge-danger">红包佣金</span>';
                    }
                    if (value === 5) {
                        return '<span class="badge badge-info">推广佣金</span>';
                    }
                }
            },
            {
                field: 'rrAllocation',
                title: '分配比例',
                formatter: function (value, row, index) {
                    if (value == null || value === '') {
                        return '-';
                    }
                    return value + '%';
                }
            },
            {
                field: 'rrSourceType',
                title: '奖励渠道',
                formatter: function (value, row, index) {
                    if (value === 1) {
                        return '日常签到';
                    }
                    if (value === 2) {
                        return '激励视频';
                    }
                }
            },
            // {
            //     field: 'rrTransId',
            //     title: '广告ID'
            // },
            {
                field: 'createTime',
                title: '奖励时间'
            }]
        // {
        //     title: '操作',
        //     align: 'center',
        //     formatter: function (value, row, index) {
        //         var actions = [];
        //         actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
        //         actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
        //         return actions.join('');
        //     }
        // }
    };
    $.ryTable.init(options);
    var createTime = $('#createTime').val();
    _ajax_query(prefix + "/statistics", {
        startTime: createTime === '' ? '' : startCreatTime,
        endTime: createTime === '' ? '' : endTime
    }, callback);
});

/*奖励记录-搜索*/
function search() {
    $('.bootstrap-table').bootstrapTable('refresh', queryParams);
    var createTime = $('#createTime').val();
    var params = {
        // 传递参数查询参数
        rrSourceType: $("#rrSourceType option:selected").val(),
        rrType: $("#rrType option:selected").val(),
        usId: $("#usId").val(),
        pusId: $("#pusId").val(),
        usNickname: $("#usNickname").val(),
        startTime: createTime === '' ? '' : startCreatTime,
        endTime: createTime === '' ? '' : endTime
    };
    _ajax_query(prefix + "/statistics", params, callback);
}

function queryParams(params) {
    var createTime = $('#createTime').val();
    return {
        // 传递参数查询参数
        pageSize: params.limit,
        pageNum: params.offset / params.limit + 1,
        searchValue: params.search,
        rrSourceType: $("#rrSourceType option:selected").val(),
        rrType: $("#rrType option:selected").val(),
        usId: $("#usId").val(),
        pusId: $("#pusId").val(),
        usNickname: $("#usNickname").val(),
        startTime: createTime === '' ? '' : startCreatTime,
        endTime: createTime === '' ? '' : endTime
    };
}

function callback(result) {
    $('label#userGoldCoin').text("金币奖励：" + result.userGoldCoin);
    $('label#userRedPacket').text("红包奖励：" + result.userRedPacket);
    $('label#moneyCommissionGoldCoins').text("金币佣金：" + result.moneyCommissionGoldCoins);
    $('label#moneyCommissionRedEnvelope').text("红包佣金：" + result.moneyCommissionRedEnvelope);
    $('label#moneyExtensionRedEnvelope').text("推广佣金：" + result.moneyExtensionRedEnvelope);
}
